<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 无障碍访问 -->
    <label for="keywords">keywords</label>
    <input type="text" id="keywords">
    <!-- 1.autofocus 2. -->
    <script>
        const input = document.querySelector('#keywords');
        // 聚焦
        // input.addEventListener('focus',function(event){
        //     console.log('foucs 表单聚焦事件')
        // })
        // 及时收集值
        input.addEventListener('input',function(){
            console.log(this.value);
        })
        // enter键
        input.addEventListener('keydown',function(event){
            // console.log(event.keyCode);
            if(event.keyCode == 13){
                console.log("提交表单");
            }
        })
        // input.focus();
    </script>
</body>
</html>